from flask import Blueprint, request, jsonify
from app.service.search_category_service  import SearchCategoryService
from utils.response_utils import ResponseUtils
from app.service.note_service import NoteService

search_category = Blueprint('search_category', __name__)

@search_category.route('/get_category_list', methods=['POST'])
def get_category_list():
    try:
        res = SearchCategoryService.get_category_list(request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)

@search_category.route('/get_category_list_by_name', methods=['POST'])
def get_category_list_by_name():
    try:
        res = SearchCategoryService.get_category_list_by_name(request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@search_category.route('/insert_category_note', methods=['POST'])
def insert_category_note():
    try:
        note_id = request.get_json().get('note_id')
        category_name = request.get_json().get('category_name')
        category_description = request.get_json().get('category_description')
        res = SearchCategoryService.insert_category_note(note_id,category_name,category_description)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@search_category.route('/insert_category', methods=['POST'])
def insert_category():
    try:
        category_name = request.get_json().get('category_name')
        res = SearchCategoryService.insert_category(category_name)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)

@search_category.route('/change_category_statu', methods=['POST'])
def change_category_statu():
    try:
        category_name = request.get_json().get('category_name')
        category_statu = request.get_json().get('category_statu')
        print('change_category_statu',category_statu,category_name)
        res = SearchCategoryService.change_category_statu(category_name,category_statu)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    

@search_category.route('/get_category_statu_list', methods=['POST'])
def get_category_statu_list():
    try:
        res = SearchCategoryService.get_category_statu_list(request)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@search_category.route('/update_category', methods=['POST'])
def update_category():
    try:
        category_name = request.get_json().get('category_name')
        category_id = request.get_json().get('category_id')
        print('category_statu',category_id,category_name)
        res = SearchCategoryService.update_category(category_name,category_id)
        return ResponseUtils.success(res)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
